<?php require_once('Connections/Connection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Recordset1 = 4;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_Connection, $Connection);
$query_Recordset1 = "SELECT caption, imgpath FROM pics";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $Connection) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Recordset1") == false && 
        stristr($param, "totalRows_Recordset1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>





<?php require "functions.php" ?>
<?php f_header("Photos") ?>

<article class="content">


  <?php if (empty ($_GET['img'])) { ?>
  
  
  <h1>Nature Album</h1>
  
  <p class="nav">
    <?php $first = TRUE; ?>
    <?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
    <?php if (!$first) { echo "&nbsp;|&nbsp;&nbsp;"; }
		else { $first = FALSE; } ?>
    <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>">First</a>
    <?php } // Show if not first page ?>
    <?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
    <?php if (!$first) { echo "&nbsp;|&nbsp;&nbsp;"; }
		else { $first = FALSE; } ?>
    <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Previous</a>
    <?php } // Show if not first page ?>
    <?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
    <?php if (!$first) { echo "&nbsp;|&nbsp;&nbsp;"; }
		else { $first = FALSE; } ?>
    <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Next</a>
    <?php } // Show if not last page ?>
    <?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
    <?php if (!$first) { echo "&nbsp;|&nbsp;&nbsp;"; }
		else { $first = FALSE; } ?>
    <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>">Last</a>
    <?php } // Show if not last page ?>
  </p>
  
  <div class="gallery">
    <?php $index = 1; ?>
    <?php do { ?>
    <a tabindex="<?php echo $index; $index = $index + 1; ?>"><img onClick="window.location = './photos.php?img=<?php echo $row_Recordset1['imgpath'] ?>'" src="<?php echo $row_Recordset1['imgpath']; ?>" width="300" height="168" href="index.php" />
    <div class="caption"><?php echo $row_Recordset1['caption']; ?></div>
    </a>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  </div><!-- end .gallery -->
  
  
  <?php } else { ?>
  
  
  <h1 class="nothing"></h1>
  <p class="nav"><a href="photos.php" style="color:black;">Back</a></p>
  <a href="<?php echo preg_replace('/_t.jpg/','.jpg',$_GET['img']) ?>"><img src="<?php echo preg_replace('/_t.jpg/','.jpg',$_GET['img']) ?>" width="535px" height="301px"></a>
  
  
  <?php } ?>
  
  
</article><!-- end .content -->

<aside>
  <h1 class="asideh">Nature Poem</h1>
  <p>I watch the waves crash in, breaking on the shore
    All their anger dispensed on the oceans floor
    I look at the sky so blue, sun shining so bright
    Spreading heat and happiness with its blinding light
    Long blades of grass swaying in the gentle breeze
    Dancing in rhythm with so much ease
    Look up at the trees hearing the singing of the birds
    Happily chirping singing at ease without words
    Sitting here holding my knees to my chest
    Watching and hearing nature at it s best</p>
</aside>

<?php f_footer() ?>

<?php mysql_free_result($Recordset1); ?>